﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace Business.Schedule
{
    public abstract class BaseScheduler : IScheduler
    {
        System.Timers.Timer timer;

        private int scheduleCount;

        public abstract Action<int> scheduleAction { get; set; }



        public const int ScheduleIntervalDefault = 1000;
        public int ScheduleCount { get => scheduleCount; set => scheduleCount = value; }
      

        public void Start()
        {
            if (timer == null)
            {
                timer = new System.Timers.Timer(ScheduleIntervalDefault);
                timer.Elapsed += Timer_Elapsed;
            }
            timer.Start();
        }

        public void Pause()
        {
            if (timer != null)
            {
                timer.Stop();
            }
        }

        public void Resume()
        {
            if (timer != null && !timer.Enabled)
            {
                timer.Start();
            }
        }

        public void Stop()
        {
            if (timer != null)
            {
                timer.Stop();
            }
        }

        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {

            Schedule();
        }

        public abstract void Schedule();

    }
}
